﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;

namespace XCommunity.Forums
{

  public class ConfigurationErrorException : Exception
  {

    public ConfigurationErrorException( string message )
    {
      _message = message;
    }

    public ConfigurationErrorException( string message, XObject wrongObject )
      : this( message )
    {
      WrongObject = wrongObject;
    }

    public XObject WrongObject
    {
      get;
      private set;
    }


    private string _message;

    public override string Message
    {
      get
      {
        if ( WrongObject == null )
          return _message;

        return _message + "\n" + GetErrorPositionInfo( WrongObject );
      }
    }

    private string GetErrorPositionInfo( XObject obj )
    {
      var info = (IXmlLineInfo) obj;

      return string.Format( "在论坛配置文件第 {0} 行第 {1} 个字符。", info.LineNumber, info.LinePosition );
    }

  }
}
